<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1038">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #bf0000}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #606060}
span.s1 {color: #1541e7}
span.s2 {color: #0d3ceb}
span.s3 {color: #0000bf}
span.s4 {color: #000000}
span.s5 {color: #606060}
span.s6 {color: #007300}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><b>PV_BufRd<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>plays FFT data from a memory buffer</b></p>
<p class="p2"><br></p>
<p class="p3"><b>PV_BufRd will play back FFT data stored to a buffer with PV_RecordBuf.</b></p>
<p class="p4"><br></p>
<p class="p3"><b>WARNING: Resynth of a FFTs with large window sizes may cause CPU spikes.</b></p>
<p class="p4"><br></p>
<p class="p3"><b>PV_RecordBuf stores FFT data to a buffer for use by a number of PV UGens. See also </b><a href="PV_RecordBuf.html"><span class="s1"><b>PV_RecordBuf</b></span></a><b>, </b><a href="PV_PlayBuf.html"><span class="s2"><b>PV_PlayBuf</b></span></a><b>, </b><a href="PV_BinPlayBuf.html"><span class="s2"><b>PV_BinPlayBuf</b></span></a><b> and </b><a href="PV_BinBufRd.html"><span class="s1"><b>PV_BinBufRd</b></span></a><b>.</b></p>
<p class="p4"><br></p>
<p class="p3"><b>PV_PlayBuf(buffer, playbuf, point, hop, wintype)</b></p>
<p class="p4"><br></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>buffer - the FFT buffer to fill data into</b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>playbuf - the buffer to read frames of FFT data fram.</b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span>point - a value between 0.0 and 1.0. 0.0 is the beginning of the file, 1.0 the end. Values greater then 1.0</b></p>
<p class="p3"><b><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>or less then 0.0 are wrapped into this range.</b></p>
<p class="p4"><b><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-converted-space"> </span></b></p>
<p class="p3"><b>Examples:</b></p>
<p class="p5"><br></p>
<p class="p6">// anazlyze a soundfile and store its data to a buffer</p>
<p class="p5"><br></p>
<p class="p7">s = Server.local;</p>
<p class="p7">s.boot;</p>
<p class="p5"><br></p>
<p class="p7">(</p>
<p class="p7"><span class="s3">var</span> sf;</p>
<p class="p6">// path to a sound file here</p>
<p class="p8"><span class="s4">p = </span>"sounds/a11wlk01.wav"<span class="s4">;</span></p>
<p class="p6">// the frame size for the analysis - experiment with other sizes (powers of 2)</p>
<p class="p7">f = 1024;<span class="Apple-converted-space"> </span></p>
<p class="p6">// the hop size</p>
<p class="p7">h = 0.25;</p>
<p class="p6">// get some info about the file</p>
<p class="p7">sf = <span class="s3">SoundFile</span>.new( p );</p>
<p class="p7">sf.openRead;</p>
<p class="p7">sf.close;</p>
<p class="p6">// allocate memory to store FFT data to... SimpleNumber.calcPVRecSize(frameSize, hop) will return<span class="Apple-converted-space"> </span></p>
<p class="p6">// the appropriate number of samples needed for the buffer</p>
<p class="p7">y = <span class="s3">Buffer</span>.alloc(s, sf.duration.calcPVRecSize(f, h));</p>
<p class="p6">// allocate the soundfile you want to analyze</p>
<p class="p7">z = <span class="s3">Buffer</span>.read(s, p);</p>
<p class="p7">)</p>
<p class="p5"><br></p>
<p class="p6">// this does the analysis and saves it to buffer 1... frees itself when done</p>
<p class="p7">(</p>
<p class="p7"><span class="s3">SynthDef</span>(<span class="s5">"pvrec"</span>, { <span class="s3">arg</span> recBuf=1, soundBufnum=2;</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s3">var</span> in, chain, bufnum;</p>
<p class="p7"><span class="Apple-tab-span">	</span>bufnum = LocalBuf.new(1024);</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s3">Line</span>.kr(1, 1, <span class="s3">BufDur</span>.kr(soundBufnum), doneAction: 2);</p>
<p class="p7"><span class="Apple-tab-span">	</span>in = <span class="s3">PlayBuf</span>.ar(1, soundBufnum, <span class="s3">BufRateScale</span>.kr(soundBufnum), loop: 0);</p>
<p class="p6"><span class="s4"><span class="Apple-tab-span">	</span></span>// note the window type and overlaps... this is important for resynth parameters</p>
<p class="p7"><span class="Apple-tab-span">	</span>chain = <span class="s3">FFT</span>(bufnum, in, 0.25, 1);<span class="Apple-converted-space"> </span></p>
<p class="p7"><span class="Apple-tab-span">	</span>chain = <span class="s3">PV_RecordBuf</span>(chain, recBuf, 0, 1, 0, 0.25, 1);</p>
<p class="p6"><span class="s4"><span class="Apple-tab-span">	</span></span>// no ouput ... simply save the analysis to recBuf</p>
<p class="p7"><span class="Apple-tab-span">	</span>}).send(s);</p>
<p class="p7">)</p>
<p class="p7">a = <span class="s3">Synth</span>(<span class="s5">"pvrec"</span>, [<span class="s6">\recBuf</span>, y, <span class="s6">\soundBufnum</span>, z]);</p>
<p class="p5"><br></p>
<p class="p6">// you can save your 'analysis' file to disk! I suggest using float32 for the format</p>
<p class="p6">// These can be read back in using Buffer.read</p>
<p class="p5"><br></p>
<p class="p8"><span class="s4">y.write(p++</span>".scpv"<span class="s4">, </span>"wav"<span class="s4">, </span>"float32"<span class="s4">);</span></p>
<p class="p5"><br></p>
<p class="p6">// play your analysis back ... see the playback UGens listed above for more examples.</p>
<p class="p7">(</p>
<p class="p7"><span class="s3">SynthDef</span>(<span class="s5">"pvplay"</span>, { <span class="s3">arg</span> out=0, recBuf=1;</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s3">var</span> in, chain, bufnum;</p>
<p class="p7"><span class="Apple-tab-span">	</span>bufnum = LocalBuf.new(1024);</p>
<p class="p7"><span class="Apple-tab-span">	</span>chain = <span class="s3">PV_BufRd</span>(bufnum, recBuf, <span class="s3">MouseX</span>.kr(0.0, 1.0));</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s3">Out</span>.ar(out, <span class="s3">IFFT</span>(chain, 1).dup);</p>
<p class="p7"><span class="Apple-tab-span">	</span>}).send(s);</p>
<p class="p7">);</p>
<p class="p7">b = <span class="s3">Synth</span>(<span class="s5">"pvplay"</span>, [<span class="s6">\out</span>, 0, <span class="s6">\bufnum</span>, x, <span class="s6">\recBuf</span>, y]);</p>
<p class="p5"><br></p>
<p class="p6">// stop the synth</p>
<p class="p7">b.free;</p>
</body>
</html>
